home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-08-09 | 120.6 KB | 5,241 lines |
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- TCHK - a Turbo C library
-
- Version 0.50
-
- Documentation for TCHK
-
- by
-
- Howard Kapustein
-
-
-
-
-
- Howard Kapustein
-
- 1695 Barbara Lane
-
- East Meadow, NY 11554
-
- (516) 481-9612
-
-
-
- (c) Copyright 1987, All rights reserved
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -1-
-
- Contents
-
-
- COPYRIGHT AND DISCLAIMER .......................................... 3
-
- TRADEMARKS ........................................................ 3
-
- LICENSE ........................................................... 3
-
- BACKGROUND ........................................................ 3
-
- FILES ............................................................. 4
-
- IN THE BEGINNING.. ................................................ 4
-
- FEATURES .......................................................... 5
-
- FUNCTIONS ......................................................... 5
- atrim - trims leading and trailing blanks .................... 7
- ltrim - trims leading blanks ................................. 7
- rtrim - trims trailing blanks ................................ 7
- box - draw a box ............................................. 8
- clear - clears a portion of the screen ....................... 9
- clear_typeahead - clear typeahead buffer ..................... 10
- cls - clear screen ........................................... 11
- cursor_flip - toggle the cursor type ......................... 12
- cursor_off - turn the cursor off ............................. 13
- cursor_on - turn the cursor on ............................... 14
- dayofyear - calculate the day of the year .................... 15
- daysleft - calculate the days left in the year ............... 16
- ddatetolong - convert a date to long string .................. 17
- ddatetoshort - convert a date to long string ................. 18
- ddatetostr - convert a date to abbrev. string ................ 19
- delay - wait for a time delay ................................ 20
- diffddate - calculate the difference in 2 dates .............. 21
- getc_match - get specific input, case independent ........... 22
- getk_match - get specific input, case dependent .............. 22
- getddate - inputs a date from the keyboard ................... 23
- getdouble - inputs a double from the keyboard ................ 24
- getfname - get a filename from the keyboard .................. 25
- getget - get a string from the keyboard w/editing ............ 26
- getint - inputs an integer from the keyboard ................. 27
- getk - get a key ............................................. 28
- getlogical - get Yes/No ...................................... 29
- getreal - inputs a real from the keyboard .................... 30
- getstr - input a string from the keyboard .................... 31
- getyn - get Yes/No ........................................... 32
- gotoxy - move cursor to coordinates (x,y) .................... 33
- horiz_line - draw a horizontal line .......................... 34
- inkey - get a key ............................................ 35
- intlen - calculate length of integer in a string ............. 36
- isCGA - is Color Graphics adapter installed .................. 37
- isEGA - is Enhanced Graphics adapter installed ............... 37
- isHerc - is Hercules Graphics adapter installed .............. 37
- isMDA - is Monochrome adapter installed ...................... 37
- isEMSavail - is EMS available ................................ 38
- isleapyear - is a year a leap year ........................... 39
- leftstr - return the left portion of string .................. 40
- midstr - return a piece of a string .......................... 40
- rightstr - return the right portion of a string .............. 40
-
-
-
-
- -2-
-
- lotus_setup - creates info for menu_lotus() .................. 41
- menu_lotus - Lotus style menu ................................ 42
- monthexpand - convert a month abbrev to its name ............. 44
- putk - put a character w/attribute on the screen ............. 45
- putsay - put a string with attribute on the screen ........... 46
- putstr - put a string with attribute on the screen ........... 47
- read_cursor - reads cursor information ....................... 48
- read_mode - find screen width, mode and page ................. 49
- restore_box - restore a part of the screen ................... 50
- restore_screen - restore screen .............................. 51
- ROM_date - gets the ROM id date .............................. 52
- ROM_id - gets the ROM id byte ................................ 53
- save_box - save a part of the screen ......................... 54
- save_screen - save screen .................................... 55
- scroll_down - scroll window down ............................. 56
- scroll_up - scroll window up ................................. 57
- set_color - set the default attribute (color) ................ 58
- set_cursor - sets cursor scan lines .......................... 59
- set_mode - set the video mode ................................ 60
- strcomma - convert a string to xx,xxx,xxx format ............. 61
- strdel - delete part of a string ............................. 62
- strins - insert one string into another ...................... 63
- strrep - replicate a char .................................... 64
- strshleft - shift string left ................................ 65
- strshright - shift string right .............................. 65
- strtoddate - convert a date string to a structure ............ 66
- strtodol - converts a string to dollar format ................ 67
- strtotime - convert a string to a time structure ............. 68
- timetostr - convert time structure to a string ............... 69
- valid_date - check if a date is valid ........................ 70
- vert_line - draw a vertical line ............................. 71
- wherex - X-coordinate of cursor ............................. 72
- wherey - y-coordinate of cursor ............................. 73
-
- #DEFINES .......................................................... 74
- Datehk.h ..................................................... 74
- Howard.h ..................................................... 74
- Ibm.h ........................................................ 74
- Math.h ....................................................... 75
- Video.h ...................................................... 75
-
- VARIABLE TYPES .................................................... 75
-
- GLOBAL VARIABLES .................................................. 76
- Keyboard variables: .......................................... 76
- Video variables: ............................................. 76
-
- FUTURE REVISIONS .................................................. 76
-
- INDEX ............................................................. 78
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -3-
-
-
-
- COPYRIGHT AND DISCLAIMER
-
- This library and documentation are Copyrighted (C) 1987 by Howard
- Kapustein, All Rights Reserved.
-
- Use of this library acknowledges this disclaimer of warranty:
- "This library is supplied as-is. The author disclaims all
- warranties, expressed or implied, including, without limitation,
- the warranties of merchantability and of fitness of this library
- for any purpose. The author assumes no liability for damages
- direct or consequential, which may result from the use of this
- library."
-
-
-
- TRADEMARKS
-
- Macintosh is a registered trademark of Apple Incorporated.
- dBase III+ is a registered trademark of Ashton-Tate Incorporated.
- Turbo C is a registered trademark of Borland International.
- Symphony is a registered trademark of Lotus Corp.
-
-
-
- LICENSE
-
- TCHK is distributed as "shareware". Nonregistered users are
- granted a limited license to use this library for personal,
- private ends, and may develop software using the functions
- contained herein, but may not distribute, sell nor otherwise
- release or profit from any product made with TCHK. Users may
- become REGISTERED owners for a small pittance of $15. Registering
- has the following benefits:
-
- Registered owners will receive TCHK compiled for use with
- all memory models (not just the small memory model
- distributed here.)
-
- Registered owners are entitled to utilize TCHK in commercial
- applications.
-
- Registered owners will automatically be registered for all
- releases up to and including 1.00 (I may extend this, but
- for now you get all releases up to 1.00.)
-
- REGISTERED owners may purchase the source code for TCHK for $25.
-
-
-
- BACKGROUND
-
- I am a student at Rensselaer Polytechnic Institute majoring in
- computer science. I also do consulting/programming work as a
- sideline (hint hint.) When I purchased Turbo C, I wanted to do
- more than bare bones printf(). I was also engaged in designing
- some software requiring the use of dates, and some other unusual
- functions. Thus, after several months of testing and use, I
- developed a rather useful collection of functions. After some
-
-
-
-
- -4-
-
- requests from other programmers, I decided to bundle most of them
- together and <gasp> document them. This library is a collection
- of most of these functions.
-
-
-
- FILES
-
- You may not distribute TCHK except in unmodified form, and it
- must be distributed with all the following files:
-
- TCHKS.LIB - small memory model library
- TCHK.DOC - documentation for TCHK
- TCHKDEMO.C - demo program of some functions
- TCHKDEMO.PRJ - project used to compile TCHKDEMO.C
- TCHK.TC - Turbo C configuration file
-
- COLOR.H - color definitions
- DATEHK.H - header file for date routines
- FILEHK.H - header file for file routines
- HOWARD.H - miscellaneous definitions
- IBM.H - header file for misc. IBM routines
- KEYBOARD.H - header file for keyboard routines
- KEYCODE.H - keyboard scan codes
- MATHHK.H - header file of math defines
- MENUHK.H - header file for menu routines
- STRINGHK.H - header file for string routines
- TIMEHK.H - header file for time routines
- VIDEO.H - header file for video routines
-
- To compile the demo program TCHKDEMO.C, load the configuration
- file TCHK.TC and the project file TCHKDEMO.PRJ and compile
- TCHK.C. Make sure you check the Turbo C directories before
- compiling.
-
-
-
- IN THE BEGINNING...
-
- Except where explicitly stated, all of these functions have been
- tested and compiled on my system:
-
- - IBM PC
- - 640K memory
- - (CGA) Color Graphics Adapter
- - DOS 3.2
-
- TCHK was compiled from the interactive environment of Turbo C,
- with the following options changed from the default:
-
- For more info, check out the configuration file TCHK.TC.
-
- This library was written in 100% Turbo C, with no use of inline
- Assembly, compiled with Turbo C 1.0 and created with PLIB86.
-
-
-
-
-
-
-
-
-
-
-
- -5-
-
- FEATURES
-
- TCHK sports many useful features not found in other shareware
- packages. Aside from many input and output routines, TCHK is the
- only package I have seen (and I've looked) that supplies date and
- time functions. Also unique to TCHK is the Lotus style slash-bar
- menu function.
-
- Many of the functions requiring output as a side effect (most
- noticeably the keyboard functions) make use of some of the output
- routines prototyped in VIDEO.H. If you use almost any of the
- keyboard routines, expect both the keyboard and the video
- routines to be linked into your program. This is true of some of
- the other routines as well (the lotus menus require the menu,
- keyboard, video and time routines.) Since the entire .LIB file is
- rather small, there is no harm done. Perhaps a future version
- will have the routines segmented more (if you really want to
- break up the library, you can always purchase the source code...)
-
-
-
- FUNCTIONS
-
- Most of the functions are documented well enough below, although
- I feel a few more explanations are necessary:
-
- In the interactive environment you can #define one item in
- terms of another, including spaces. If anyone knows how to
- do this with the command line version, please let me know.
- The variable type byte is just an unsigned char. If you
- use the command line version of TC you will have to change
- the header files of TCHK.
-
- All functions asking for screen coordinates treat the top
- left corner as row zero, column zero (0,0).
-
- Most functions rely on interrupts and low memory addresses
- (400:xxxx) to comply with the IBM standard. Certain values
- (for instance, the current video page) can be found by an
- interrupt or by peeking at the value stored in low memory.
- Many of the video functions especially require these values
- to be found at the proper places. If your clone is radically
- different from the IBM standard some of these functions may
- not work properly. I didn't want to have to write a million
- small functions that are just background support for the
- functions found here (like current page number, etc.) so I
- used the #defines found in the headers (see video.h for more
- details.)
-
- TCHK has not been tested on a Hercules or MDA video card
- since I do not have access to either piece of hardware,
- although the methods are well documented and should cause no
- problems.
-
- All direct screen accesses have built-in snow control. On
- CGA monitors, the snow was horrendous without it. Unless I
- code these routines in assembler, I won't be able to squeeze
- any more optimization out of these routines. I do plan on
- converting these functions to assembler, but I just don't
- have the time right now.
-
-
-
-
- -6-
-
-
- One type of command you will NOT find in TCHK are windowing
- commands. There are plenty of windowing libraries available. You
- should not try to make your poor IBM into a Mac, it won't cut it.
- Splurge for the Mac, you'll be happier. Yes, I know, the
- 'windowing' interface is nicer. I use 'windows' too, although
- mine are just boxes. I find it more than suitable for my current
- needs.
-
- The functions are listed in the same manner as the Turbo C
- manual, in alphabetical order.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -7-
-
-
- Name atrim - trims leading and trailing blanks
- ltrim - trims leading blanks
- rtrim - trims trailing blanks
-
- Usage char *atrim(char *source);
- char *ltrim(char *source);
- char *rtrim(char *source);
-
- Prototype in stringhk.h
-
- Description these functions remove leading and/or trailing
- blanks in a string.
-
- Return value returns a pointer to the storage location
- containing the trimmed string, or NULL if space
- could not be allocated. The returned string is NOT
- the same as the string passed to the function.
- This function does NOT write over the string
- passed to it.
-
-
- Example #include <stringhk.h>
- #include <stdio.h> /* for the printf */
-
- main()
- {
- char msg[25], *trimmed
-
- strcpy(msg," Hello everyone ");
- trimmed = ltrim(msg);
- printf("String [%s]\n",msg);
- printf("ltrim [%s]\n",trimmed);
- free(trimmed);
- trimmed = rtrim(msg);
- printf("rtrim [%s]\n",trimmmed);
- free(trimmed);
- trimmed = atrim(msg);
- printf("atrim [%s]\n",trimmmed);
- }
-
- Program output String [ Hello everyone ]
- ltrim [Hello everyone ]
- rtrim [ Hello everyone]
- atrim [Hello everyone]
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -8-
-
-
- Name box - draw a box
-
- Usage int box(int top, int left, int bottom, int right,
- byte frame[]);
-
-
- Prototype in video.h
-
- Description draws a box via INTerrupts.
- frame must be have at leeast 9 elements (byte
- frame[9]). The box characters are frame[0] (top
- left) to frame[7] (left wall), going clockwise. If
- frame[8] != '\0' the box is filled with it.
-
- Return value returns zero upon succesful completion, -1 if
- invalid coordinates are given.
-
- See also global variables
- horiz_line(), restore_box(), restore_screen(),
- save_box(), save_screen(), vert_line()
-
- Example #include <video.h>
-
- main()
- {
- byte framebox[9];
-
- strcpy(framebox,"abcdefghi");
- box(1,4,4,10,framebox);
- }
-
- Program output abbbbbc
- hiiiiid
- hiiiiid
- gfffffe
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -9-
-
-
- Name clear - clears a portion of the screen
-
- Usage void clear(int top, int left, int bottom, int
- right);
-
- Prototype in video.h
-
- Description clears a box of the screen with INT 0x10, Service
- 6.
-
- Return value nothing.
-
- See also cls()
-
- Example #include <video.h>
-
- main()
- {
- clear(0,0,3,79); /* clear top 4 lines of
- screen */
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -10-
-
-
- Name clear_typeahead - clear typeahead buffer
-
- Usage int clear_typeahead(void);
-
- Prototype in keyboard.h
-
- Description clears the typeahead buffer and returns the number
- of keystrokes cleared
-
- Return value number of keystrokes emptied from the typeahead
- buffer
-
- Example #include <keyboard.h>
- #include <stdio.h>
-
- main()
- {
- printf("# keystrokes emptied = %d",
- clear_typeahead());
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -11-
-
-
- Name cls - clear screen
-
- Usage void cls(void);
-
- Prototype in video.h
-
- Description clears screen by INT 0x10, Service 6 (scroll
- window up) and resets cursor to (0,0).
-
- Return value nothing.
-
- See also clear()
-
- Example #include <video.h>
-
- main()
- {
- cls()
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -12-
-
-
- Name cursor_flip - toggle the cursor type
-
- Usage void cursor_flip(unsigned int curs1, unsigned int
- curs2);
-
- Prototype in video.h
-
- Description toggles the cursor scan lines to whichever set the
- cursor is not currently set for.
-
- Return value nothing.
-
- See also cursor_off(), cursor_on(), read_cursor(),
- set_cursor()
-
- Example #include <video.h>
-
- main()
- {
- cursor_flip(CURSOR_UNDERBAR,CURSOR_HALFBLOCK);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -13-
-
-
- Name cursor_off - turn the cursor off
-
- Usage void cursor_off(void);
-
- Prototype in video.h
-
- Description makes the cursor invisible.
-
- Return value nothing.
-
- See also cursor_flip(), cursor_on(), read_cursor(),
- set_cursor()
-
- Example #include <video.h>
-
- main()
- {
- cursor_off();
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -14-
-
-
- Name cursor_on - turn the cursor on
-
- Usage void cursor_on(void);
-
- Prototype in video.h
-
- Description makes the cursor visible. Sets the scan lines to
- the default according to the hardware detected.
-
- Return value nothing.
-
- See also cursor_flip(), cursor_off(), read_cursor(),
- set_cursor()
-
- Example #include <video.h>
-
- main()
- {
- cursor_on();
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -15-
-
-
- Name dayofyear - calculate the day of the year
-
- Usage int dayofyear(struct ddate *d);
-
- Prototype in datehk.h
-
- Description dayofyear calculate the day of the year given a
- date. The day of the year will range from 1
- (January 1) to 365 (Dec 31, no leap year) or 366
- (Dec 31, leap year.)
-
- dayofyear does no error checking on passed
- parameters.
-
- Return value returns a number from 1 to 365 (no leap year) or
- 366 (leap year.)
-
- See also daysleft(), diffddate()
-
- Example #include <datehk.h>
-
- main()
- {
- struct ddate today;
-
- /* set today to Feb 3, 1987 */
- printf("%d/%d = day %d\n", today.dmon,
- today.dday, dayofyear(&today));
- }
-
- Program output 2/3 = day 34
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -16-
-
-
- Name daysleft - calculate the days left in the year
-
- Usage int daysleft(struct ddate *d);
-
- Prototype in datehk.h
-
- Description daysleft calculates how many more days are left in
- the year. The days left will range from 0 (Dec 31)
- to 364 (Jan 1, no leap year) or 365 (Jan 1, leap
- year.)
-
- daysleft does no error checking on passed
- parameters.
-
- Return value returns a number from 0 to 364 (no leap year) or
- 365 (leap year.)
-
- See also dayofyear(), diffddate()
-
- Example #include <datehk.h>
-
- main()
- {
- struct ddate today;
-
- /* set today to Nov 3, 1987 */
- printf("%d/%d = %d days left\n", today.dmon,
- today.dday, daysleft(&today));
- }
-
- Program output 11/3 = 58 days left
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -17-
-
-
- Name ddatetolong - convert a date to long string
-
- Usage char *ddatetolong(struct ddate *source);
-
- Prototype in datehk.h
-
- Description ddatetolong converts a date from the structure
- format ddate to a string in the form
- Month dd, Year where
-
- Month = the name of the month ("November")
- dd = the day (5, 12, etc.)
- Year = the year + 1900
-
- Return value returns a pointer to the storage location
- containing the date in string format, or NULL if
- space could not be allocated.
-
- See also ddatetoshort(), ddatetostr(), monthexpand(),
- strtoddate()
-
- Example #include <datehk.h>
-
- main()
- {
- struct ddate today;
- char *strtoday;
-
- /* assign some value to today */
- strtoday = ddatetolong(&today);
- printf("today is %d-%d-%d\n", today.dmon,
- today.dday, today.dyear);
- printf("or %s\n", (strtoday==NULL) ?
- "no memory" : strtoday);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -18-
-
-
- Name ddatetoshort - convert a date to long string
-
- Usage char *ddatetoshort(struct ddate *source);
-
- Prototype in datehk.h
-
- Description ddatetoshort converts a date from the structure
- format ddate to a string in the form
- Mon dd, Year where
-
- Mon = the abbreviation of the month ("Nov")
- dd = the day (5, 12, etc.)
- Year = the year + 1900
-
- Return value returns a pointer to the storage location
- containing the date in string format, or NULL if
- space could not be allocated.
-
- See also ddatetolong(), ddatetostr(), monthexpand(),
- strtoddate()
-
- Example #include <datehk.h>
-
- main()
- {
- struct ddate today;
- char *strtoday;
-
- /* assign some value to today */
- strtoday = ddatetoshort(&today);
- printf("today is %d-%d-%d\n", today.dmon,
- today.dday, today.dyear);
- printf("or %s\n", (strtoday==NULL) ?
- "no memory" : strtoday);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -19-
-
-
- Name ddatetostr - convert a date to abbrev. string
-
- Usage char *ddatetostr(struct ddate *source);
-
- Prototype in datehk.h
-
- Description ddatetostr converts a date from the structure
- format ddate to a string in the form mm-dd-y..y
- where the month and day are always 2 digits long
- (a 0 is prefix to single digit months and days)
- and year is not altered.
-
- Return value returns a pointer to the storage location
- containing the date in string format, or NULL if
- space could not be allocated.
-
- See also ddatetolong(), ddatetoshort(), monthexpand(),
- strtoddate()
-
- Example #include <datehk.h>
-
- main()
- {
- struct ddate today;
- char *strtoday;
-
- /* assign some value to today */
- strtoday = ddatetostr(&today);
- printf("today is %d-%d-%d\n", today.dmon,
- today.dday, today.dyear);
- printf("or %s\n", (strtoday==NULL) ?
- "no memory" : strtoday);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -20-
-
-
- Name delay - wait for a time delay
-
- Usage void delay(int wait);
-
- Prototype in timehk.h
-
- Description delay is an empty loop based on the clock that
- waits for wait/10 seconds.
-
- wait can be any positive int value (the maximium
- wait 32767 is a little less than an hour.) If wait
- is negative, erratic behavior may result (it won't
- work.)
-
- Return value nothing.
-
- Example #include <timehk.h>
-
- main()
- {
- delay(5); /* wait for 1/2 second */
- delay(600); /* wait for one minute */
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -21-
-
-
- Name diffddate - calculate the difference in 2 dates
-
- Usage long int diffddate(struct ddate *start,
- struct ddate *fini);
-
- Prototype in datehk.h
-
- Description diffdate calculates the difference in days between
- start and fini (fini - start).
-
- diffdate does not perform any error checking on
- the passed parameters.
-
- Return value returns the number of days from start to fini.
-
- See also dayofyear(), daysleft(), diffddate()
-
- Example #include <datehk.h>
-
- main()
- {
- struct ddate begin, end;
- long int days;
-
- /* set begin to Jan 1, 1981 */
- /* set end to Feb 5, 1982 */
- days = diffdate(&begin,&end);
- printf("Feb 5, 1982 - Jan 1, 1981 =
- %ld\n",days);
- }
-
- Program output Feb 5, 1982 - Jan 1, 1981 = 400
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -22-
-
-
- Name getc_match - get specific input, case
- independent
- getk_match - get specific input, case dependent
-
- Usage char getc_match(boolean output, char *match);
- char getk_match(boolean output, char *match);
-
- Prototype in keyboard.h
-
- Description these functions accept character input (via
- getk()) until one of the characters in the string
- match in entered. getk_match waits for an
- identical match ('a' != 'A') and getc_match waits
- for a similar match ('a' == 'A'). Extended keys
- never match (F10 will never be a match.) If output
- = TRUE, the character is echoed to the screen via
- putk().
-
- Return value returns the key pressed.
-
- See also getk(), getlogical(), getyn()
-
- Example #include <keyboard.h>
-
- main()
- {
- printf("Enter your choice (Q, X, F, D): ");
- getc_match(1,"QXFD");
- printf("Enter your sub-choice (abcdHJ): ");
- getk_match(1,"abcdHJ");
- }
-
- Program output Enter your choice (Q, X, F, D): f
- Enter your subchoice (abcdHJ): H
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -23-
-
-
- Name getddate - inputs a date from the keyboard
-
- Usage char *getddate(void);
-
- Prototype in keyboard.h
-
- Description getddate inputs a date from the keyboard in the
- form xx-xx-xx. Only digits, space and backspace
- are valid input. Input is terminated when the
- ENTER key is pressed. Input is echoed to the
- screen via putk().
-
- Return value if a valid date is entered, getddate returns a
- string in the form xx-xx-xx, otherwise NULL is
- returned.
-
- Example #include <keyboard.h>
- #include <stdio.h>
- main()
- {
- char *c;
-
- printf("What is today's date: ");
- c = getddate();
- printf("Today is %s\n",c);
- }
-
- Program output What is today's date: 11-10-87
- Today is 11-10-87
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -24-
-
-
- Name getdouble - inputs a double from the keyboard
-
- Usage char *getdouble(void);
-
- Prototype in keyboard.h
-
- Description getdouble inputs a double from the keyboard. Only
- digits, decimal point, leading sign and backspace
- are valid input. Input is terminated when the
- ENTER key is pressed. Input is echoed to the
- screen via putk().
-
- The maximum length of input is 25.
-
- Return value returns a string of the format [sn] [ddd] [.]
- [ddd] where
-
- [sn] = optional sign (+ or -)
- [ddd] = optional digits
- [.] = optional decimal point
-
- See also getint(), getreal()
-
- Example #include <keyboard.h>
- #include <stdio.h>
- main()
- {
- char *c;
-
- printf("Give me a double: ");
- c = getdouble();
- printf("Your input is %s\n",c);
- }
-
- Program output Give me a double: -1289.12003
- Your input is -1289.12003
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -25-
-
-
- Name getfname - get a filename from the keyboard
-
- Usage int getfname(byte row, byte col, char *returnstr,
- char *pattern, int argn, int argk[]);
-
- Prototype in video.h
-
- Description getfname calls getget() asking for input of a
- length 12 string, at the coordinates (col,row),
- including pattern formatting and optional input
- exit keys listed in argk. If memory was allocated
- for returnstr, the string pointed to by returnstr
- is checked to see if it is a valid DOS filename. A
- valid filename must be of the form
- [filename] [.] [ext] and does not contain
- any of the following:
-
- [ ] ; , . / ? * : " + = - < > \ |
-
- If memory could not be allocated for the string,
- returnstr will be set to NULL.
-
- For more info on pattern and argk requirements,
- check the stats for getget().
-
- Return value if memory could not be allocated for returnstr or
- the string pointed to by returnstr is not a valid
- filename, -1 is returned, otherwise the key used
- to exit the input is returned.
-
- See also getget()
-
- Example #include <filehk.h>
- #include <keycode.h>
-
- main()
- {
- char *fname;
- int keys[2]={ESC,F10}; /* ESC & F10 exit
- input */
-
- gotoxy(0,0);
- printf("Enter file: ");
- if (getfname(0,13,fname,"!",2,keys) == -1)
- printf(" BAD FILENAME");
- else
- printf(" valid filename");
- }
-
- Program output
-
-
-
-
-
-
-
-
-
-
-
-
-
- -26-
-
-
- Name getget - get a string from the keyboard
- w/editing
-
- Usage int getget(byte row, byte col, char *returnstr,
- int size, char *pattern, int argn,
- int argk[]);
-
- Prototype in keyboard.h
-
- Description getget inputs a string at coordinates (col,row),
- of maximum length size, formatted according to
- pattern. Input ends when ENTER or one of the scan
- codes specified in argk[] in inputted. There are
- argn number of elements in argk[]. The string is
- returned in returnstr and the function returns the
- scan code of the exiting key.
-
- Full feature editing of the string includes:
-
- ENTER Ends input, exits function
- BACKSPACE normal backspace
- LEFT ARROW move cursor back 1 character
- INSERT toggle inset/overwrite mode
- DELETE delete character under cursor
- RIGHT ARROW move cursor forward 1
- character
- HOME move cursor to beginning for
- string
- END move cursor to end of string
- CTRL-Y delete entire string
- ALT-Y delete string from cursor to
- end
-
- See getstr() for pattern arguments.
-
- Return value returns the scan code of the key causing the exit
-
- See also getstr()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -27-
-
-
- Name getint - inputs an integer from the keyboard
-
- Usage char *getint(void);
-
- Prototype in keyboard.h
-
- Description getint inputs an integer from the keyboard. Only
- digits, leading sign and backspace are valid
- input. Input is terminated when the ENTER key is
- pressed. Input is echoed to the screen via putk().
-
- the maximum length of input is 25.
-
- Return value returns a string of the format [sn] [ddd] where
-
- [sn] = optional sign (+ or -)
- [ddd] = optional digits
-
- See also getdouble(), getreal()
-
- Example #include <keyboard.h>
- #include <stdio.h>
- main()
- {
- char *c;
-
- printf("Give me an integer: ");
- c = getint();
- printf("Your input is %s\n",c);
- }
-
- Program output Give me an integer: -1289
- Your input is -1289
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -28-
-
-
- Name getk - get a key
-
- Usage byte getk(boolean wait);
-
- Prototype in keyboard.h
-
- Description getk returns the scan code of the key pressed. If
- no key was pressed (WAIT = FALSE) 0 is returned.
- This function is similar to getchar() except input
- is not echoed to the screen and getk will detect
- any key press (any standard keypress. It cannot
- distinguish between the grey '+' key and the white
- '+'. This function is interrupt driven. It will
- detect ALT combinations, Del, PgUp, function keys,
- etc., any keyboard INTerrupt accepted keys.
-
- Return value returns the scancode for the key pressed, from 1
- to 255. If WAIT = FALSE, and no key is pressed,
- zero is returned. Check the global variables
- key_status and key_extended to determine the shift
- key status and if the key is an extended one.
-
- See also keycode.h
- getc_match(), getk_match(), getlogical(), getyn(),
- inkey()
-
- Example #include <keyboard.h>
- #include <stdio.h>
-
- main()
- {
- extern boolean key_extended;
- byte c;
-
- c = getk(WAIT);
- printf("Key code # in keycode.h: %d\n",
- key_extended ? c+256 : c);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -29-
-
-
- Name getlogical - get Yes/No
-
- Usage char getlogical(int output);
-
- Prototype in keyboard.h
-
- Description getlogical waits for a True/False key (TtFfYyNn)
- to be pressed and then displays a message via
- putstr() according to output:
-
- output Message displayed
- ------ -----------------
- 0 no message
- 1 T or F or Y or N
- 2 True or False or Yes or No
-
- getlogical is case independent.
-
- Return value returns 'Y' or 'N'
-
- See also getc_match(), getk(), getk_match(), getyn(),
- inkey()
-
- Example #include <keyboard.h>
-
- main()
- {
- printf("This is good? ");
- getlogical(2);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -30-
-
-
- Name getreal - inputs a real from the keyboard
-
- Usage char *getreal(int size, int decimal);
-
- Prototype in keyboard.h
-
- Description getreal inputs a real (double) from the keyboard.
- Only digits, decimal place, leading sign and
- backspace are valid input. Input is terminated
- when the ENTER key is pressed. Input is echoed to
- the screen via putk().
-
- the maximum length of input is size and the
- maximum number of decimal places is decimal. When
- calculating size, you must leave enough room for
- decimal, plus the number of places of the leading
- integer, one for the decimal point and one for the
- leading sign.
-
- Return value returns a string of the format [sn] [ddd] [.]
- [ddd] where
-
- [sn] = optional sign (+ or -)
- [ddd] = optional digits
- [.] = optional decimal point
-
- See also getdouble(), getint()
-
- Example #include <keyboard.h>
- #include <stdio.h>
- main()
- {
- char *c;
-
- printf("Give me a real: ");
- c = getreal(8,2);
- printf("Your input is %s\n",c);
- }
-
- Program output Give me a real: -1012.30
- Your input is -1012.30
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -31-
-
-
- Name getstr - input a string from the keyboard
-
- Usage char *getstr(int size, char *pattern);
-
- Prototype in keyboard.h
-
- Description getstr inputs a string from the keyboard, of
- maximum length size, given a format pattern where
-
- pattern format
- ------- ------
- Types a Alphabetic
- A Alphabetic and
- capitalized
- n Alphanumeric
- N Alphanumeric and
- capitalized
- X Ascii (default)
- 9 Numeric
- # Numeric and punctuation
-
- Modifiers ! convert to upper case
- . punctuation
- ( left justify
- ) right justify
- ^ center justify
-
- The only other valid keys are backspace and ENTER.
- Input is echoed to the screen via putk().
-
- Return value returns a pointer to the storage location
- containing the formatted string, or NULL if space
- could not be allocated.
-
- See also getget()
-
- Example #include <keyboard.h>
- #include <stdio.h>
-
- main()
- {
- char *f, *l, *s, *c;
-
- printf("First name: ");
- f = getget(10,"A");
- printf("Last name: ");
- l = getget(20,"a");
- printf("SS#: ");
- s = getget(8,"9");
- printf("Comments: ");
- c = getget(60,"");
- }
-
- Program output First name: HOWARD
- Last name: kapustein
- SS#: 123456789
- Comments: The empty quotes defaults to X.
-
-
-
-
-
-
- -32-
-
-
- Name getyn - get Yes/No
-
- Usage char getyn(int output);
-
- Prototype in keyboard.h
-
- Description getyn waits for a Y or N to be pressed and then
- displays a message via putstr() according to
- output:
-
- output Message displayed
- ------ -----------------
- 0 no message
- 1 Y or N
- 2 Yes or No
-
- getyn is case independent.
-
- Return value returns 'Y' or 'N'
-
- See also getc_match(), getk(), getk_match(), getlogical(),
- inkey()
-
- Example #include <keyboard.h>
-
- main()
- {
- printf("Is this OK? ");
- getyn(2);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -33-
-
-
- Name gotoxy - move cursor to coordinates (x,y)
-
- Usage void gotoxy(int x, int y);
-
- Prototype in video.h
-
- Description gotoxy puts cursor at coordinates (x,y) via INT
- 0x10, Service 2.
-
- Return value nothing.
-
- See also read_cursor(), wherex(), wherey()
-
- Example #include <video.h>
-
- main()
- {
- gotoxy(4,10); /* put cursor at row 4,
- column 10 */
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -34-
-
-
- Name horiz_line - draw a horizontal line
-
- Usage void horiz_line(byte c, unsigned int len, byte
- row,
- byte col);
-
- Prototype in video.h
-
- Description draws a horizontal line of characters c of length
- len beginning at (col,row) via INTerrupts.
-
- horiz_line does no error checking on the passed
- parameters.
-
- Return value nothing.
-
- See also box(), restore_box(), restore_screen(),
- save_box(), save_screen(), vert_line()
-
- Example #include <video.h>
-
- main()
- {
- horiz_line('*',7,4,4); /* draw 7 *'s at
- (4,4) */
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -35-
-
-
- Name inkey - get a key
-
- Usage int inkey(boolean wait);
-
- Prototype in keyboard.h
-
- Description inkey returns the scan code of the key pressed. If
- no key was pressed (WAIT = FALSE) 0 is returned.
- This function is similar to getchar() except input
- is not echoed to the screen and getk will detect
- any key press (any standard keypress. It cannot
- distinguish between the grey '+' key and the white
- '+'. This function is interrupt driven. It will
- detect ALT combinations, Del, PgUp, function keys,
- etc., any keyboard INTerrupt accepted keys.
- /* IBM.c - IBM specific info functions: machine ID, etc. */
-
- #include <howard.h>
- #include <dos.h>
- #include <ibm.h>
- #include <alloc.h>
- #include <stdio.h>
-
-
- /* function prototypes */
- byte IBM_id(void); /* get ROM id */
- char *IBM_date(void); /* get ROM date */
- boolean isEMSavail(void); /* is EMS available */
- /*void reboot(boolean warmboot); /* reboot, warmboot vs. coldboot */*/
-
-
- byte ROM_id(void) /* get ROM id */
- {
- return (peekb(0xF000, 0xFFFE));
- }
-
-
- char *ROM_date(void) /* get ROM date */
- {
- int i;
- char *retval;
-
- if ((retval = (char *) calloc (9,sizeof(char))) == NULL)
- return(NULL);
- for (i=0; i<8; i++)
- *(retval+i) = peekb(0xF000, 0xFFF5 + i);
- *(retval+8) = '\0';
- return(retval);
- }
- /*
-
- void reboot(boolean warmboot) /* reboot, warmboot vs. coldboot */
- {
- int *bootme();
-
- if (warmboot)
- *((int far *) 0x472lu) = 0x1234; /* forces warm boot */
-
- (long)bootme = 0xFFFF0000l; /* segment:offset addr of BIOS RAM (FFFF:0000) */
- (*bootme)(); /* reboot */
- }
- */
-
-
- boolean isEMSavail(void) /* is EMS available */
- {
- FILE *fp;
-
- if ((fp = fopen("EMMXXXX0","r")) == NULL) /* no EMS device */
- return(FALSE);
- fclose(fp); /* close opened EMS device */
- return(TRUE);
- }
-
-
- main(){printf("EMS: %d\n",isEMSavail()?1:0);} ╒UU └ %UUUU≡